package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.service.NursingPlanService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingLevelImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    //查询所有护理等级
    @Override
    public List<NursingLevelVo> queryNursingLevelAll() {
        return nursingLevelMapper.queryNursingLevelAll();
    }

    //新增护理计划
    @Transactional
    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        bean.setStatus(0);
        nursingLevelMapper.addNursingLevel(bean);
//        nursingPlanService.add(nursingplans);
    }

    //分页查询护理等级
    @Override
    public PageResponse<NursingLevelVo> queryNursingLevelByPage(String name, Integer pageNum, Integer pageSize ,Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.queryNursingLevelByPage(name,status);
        return PageResponse.of(page,NursingLevelVo.class);
    }

    //id查询护理等级
    @Override
    public NursingLevelVo getNursingLevelById(Long id) {
        NursingLevelVo level = nursingLevelMapper.getNursingLevelById(id);
        return level;
    }

    //修改护理等级
    @Override
    public void updateNursingLevel(NursingLevelVo nursingLevelVo) {
        nursingLevelMapper.updateNursingLevel(nursingLevelVo);
    }

    //删除护理等级
    @Override
    public void deleteNursingLevel(Long id) {
        nursingLevelMapper.deleteNursingLevel(id);
    }

    //启用禁用护理等级
    @Override
    public void updateNursingLevelStatus(Long id, Integer status) {
        if (status == 0)
            nursingLevelMapper.updateNursingLevelStatus(id,1);
        else
            nursingLevelMapper.updateNursingLevelStatus(id,0);
    }
}















